﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using System.Windows.Threading;

namespace Presentation.Infrastructure
{
    public static class Extensions
    {
        public static void AddAsync<TItem>(this ObservableCollection<TItem> target, TItem item)
        {
            Application.Current.Dispatcher.BeginInvoke(new Action<TItem>(target.Add), DispatcherPriority.Background, item);
        }

        public static void AddRangeAsync<TItem>(this ObservableCollection<TItem> target, IEnumerable<TItem> items)
        {
            items.ToList().ForEach(it => AddAsync(target, it));
        }
    }
}
